﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using TRPOP.CMS.Model;
using System.Data;
using System.IO;
using TRPOP.Config;
using TRPOP.Common;

namespace TRPOP.CMS.Plugin.Config
{
    /// <summary>
    /// 菜单操作方法
    /// </summary>
    public class MenuConfig
    {
        /// <summary>
        /// 系统菜单配置文件
        /// </summary>
        static string m_strPath = SystemConst.SystemMenu_FileName;

        /// <summary>
        ///  获取某结点类型下的所有变量集合
        /// </summary>      
        /// <param name="NodeListPath">结点路径</param>
        /// <returns></returns>
        public static DataTable GetDataSource(string NodeListPath)
        {
            if (!File.Exists(m_strPath))
            {
                return null;
            }
            return ConfigManage.GetDataSource(m_strPath, NodeListPath);
        }

        /// <summary>
        /// 获取头部菜单
        /// </summary>
        public static DataTable HeadMenus
        {
            get
            {

                DataTable dt = GetDataSource("//headmenu");

                if (dt != null)
                {
                    dt.DefaultView.Sort = " menuid asc";
                }
                return dt.DefaultView.Table;
            }
        }

        /// <summary>
        /// 获取子菜单
        /// </summary>
        /// <param name="headname"></param>
        /// <returns></returns>
        public static DataTable GetLeftMenuByHeadName(string headname)
        {
            DataTable dt = GetDataSource("//submenus//" + headname);
            if (dt != null)
            {
                dt.DefaultView.Sort = " menuid asc";
            }

            return dt;
        }

        /// <summary>
        /// 结点的右键菜单
        /// </summary>
        /// <param name="name"></param>
        /// <returns></returns>
        public static DataTable GetContextMenu(string name)
        {
            return GetDataSource("//contextmenu//" + name);
        }
    }
}
